﻿using System.IO;
using UnityEngine;

namespace com.yd.sdk
{
    public static class Constants
    {
        internal static bool _isUsePackageCache = true;
        internal static string _rootPath = "";
        
        //"com.unity.example": "https://github.com/DenseOoFog/AdmobTest.git?path=/com.densefog.admob",
        //public static string ADMOB_SDK_GITURL = "https://github.com/DenseOoFog/AdmobTest.git?path=/com.densefog.admob";
        public static string SDK_PACKAGENAME = "com.yd.sdk";
        
        public static string ANDROID_PLUGINS_PATH = "/Plugins/Android/";
        public static string ANDROID_PLUGINS_RES_VALUE_PATH = "/Plugins/Android/res/values/";
        public static string ANDROID_PLUGINS_RES_STRING_PATH = "/Plugins/Android/res/xml/";
        
        public static string ANDROID_MAIN_TEMPLATE_PATH = ANDROID_PLUGINS_PATH + "mainTemplate.gradle";
        public static string ANDROID_MAIN_SDK_DEPENDENCIES= "implementation 'com.yd.sdk:main:1.0.0'";
        
        // baseProjectTemplate
        public static string ANDROID_BASE_TEMPLATE_PATH = ANDROID_PLUGINS_PATH + "baseProjectTemplate.gradle";
        public static string ORIGIN_BASE_TEMPLATE = "/Packages/yd_sdkmanager/Resources/baseProjectTemplate.gradle";
        
        // launcherTemplate
        public static string ANDROID_LAUNCHER_TEMPLATE_PATH = ANDROID_PLUGINS_PATH + "launcherTemplate.gradle";
        public static string ORIGIN_LAUNCHER_TEMPLATE = "/Packages/yd_sdkmanager/Resources/launcherTemplate.gradle";
        
        // gradleTemplate
        public static string ANDROID_GRADLE_TEMPLATE_PATH = ANDROID_PLUGINS_PATH + "gradleTemplate.properties";
        public static string ORIGIN_GRADLE_TEMPLATE_PATH = "/Packages/yd_sdkmanager/Resources/gradleTemplate.properties";
        
        //proguard-user
        public static string ANDROID_PROGUARD_USER_PATH = ANDROID_PLUGINS_PATH + "proguard-user.txt";
        public static string ORIGIN_PROGUARD_USER_PATH = "/Packages/yd_sdkmanager/Resources/proguard-user.txt";
        
        
        //初始包manifest
        public static string ORIGIN_PACKAGE_MANIFEST = "/Packages/yd_sdkmanager/Resources/manifest.json";
        //manifest路径
        public static string PACKAGE_MANIFEST = "/Packages/manifest.json";
        
        //初始AndroidManifest
        public static string ORIGIN_ANDROID_MANIFEST = "/Packages/yd_sdkmanager/Resources/AndroidManifest.xml.disable";
        //AndroidManifest路径
        public static string ANDROID_MAIN_MANIFEST = "/Plugins/Android/AndroidManifest.xml";

        //初始GRADLE路径
        public static string ORIGIN_MAIN_TEMPLATE_GRADLE = "/Packages/yd_sdkmanager/Resources/mainTemplate.gradle.disable";
       
        
        #region Google Billing
        
        public static string BILLINGS_DEPENDENCIES= "implementation 'com.android.billingclient:billing:3.0.3'";
        public static string BILLINGS_IMP_DEPENDENCIES= "implementation 'com.yd.sdk:payimp:1.0.0'";
        //谷歌支付AndroidManifest
        public static string GOOGLE_BILLING_MANIFEST =
            "/Packages/yd_sdkmanager/Plugins/Android/GoogleBilling/AndroidManifest.xml";

        #endregion

        
        
        #region Admob
        
        public static string ADMOB_DEPENDENCIES= "implementation 'com.google.android.gms:play-services-ads:20.2.0'";
        public static string ADMOB_IMP_DEPENDENCIES= "implementation 'com.yd.sdk:adimp:1.0.0'";
        //AndroidManifest
        public static string ADMOB_MANIFEST =
            "/Packages/yd_sdkmanager/Plugins/Android/Admob/AndroidManifest.xml";

        
        
        #region Admob_Mediation_Facebook
        
        public static string ADMOB_MEDIATION_FACEBOOK_DEPENDENCIES = "implementation 'com.google.ads.mediation:facebook:6.6.0.0'";
        //Facebook's Android network security config
        public static string ADMOB_MEDIATION_FACEBOOK_XML =
            "/Packages/yd_sdkmanager/Plugins/Android/Admob/Facebook/res/xml/network_security_config.xml";
        #endregion

        #region Admob_Mediation_Unity

        public static string ADMOB_MEDIATION_UNITY_DEPENDENCIES =
            "implementation 'com.unity3d.ads:unity-ads:4.0.0'\n" +  "\timplementation 'com.google.ads.mediation:unity:4.0.0.0'";
        

        #endregion


        #region Admob_Mediation_Mintegral

        public static string ADMOB_MEDIATION_MTG_DEPENDENCIES = "implementation 'com.mbridge.msdk.oversea:videojs:16.0.11'\n\t" +
        "implementation 'com.mbridge.msdk.oversea:mbjscommon:16.0.11'\n\t" +
        "implementation 'com.mbridge.msdk.oversea:playercommon:16.0.11'\n\t" +
        "implementation 'com.mbridge.msdk.oversea:reward:16.0.11'\n\t" +
        "implementation 'com.mbridge.msdk.oversea:videocommon:16.0.11'\n\t" +
        "implementation 'com.mbridge.msdk.oversea:same:16.0.11'\n\t" +
        "implementation 'com.mbridge.msdk.oversea:interstitialvideo:16.0.11'\n\t" +
        "implementation 'com.mbridge.msdk.oversea:interstitial:16.0.11'\n\t" +
        "implementation 'com.mbridge.msdk.oversea:mbbanner:16.0.11'";

        
        public static string ADMOB_MEDIATION_MTG_ADAPT =
            "/Packages/yd_sdkmanager/Plugins/Android/Admob/MTG/admob_adapter-3.0.0.aar";
        
        #endregion

        #region Admob_Mediation_Pangle

        public static string ADMOB_MEDIATION_PANGLE_DEPENDENCIES = "implementation 'com.pangle.global:ads-sdk:4.2.5.2'\n\t" +
                                                                   "implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'\n\t" +
                                                                   "implementation 'com.yd.sdk:adpangle:1.0.0'";

        #endregion


        #region Admob_Mediation_APPLOVIN
        public static string ADMOB_MEDIATION_APPLOVIN_DEPENDENCIES = "implementation 'com.google.ads.mediation:applovin:11.1.0.0'";
        

        #endregion
        
        
        
        
        
        
        #endregion

        
        
        public static string ADMOB_MEDIATION_FYBER_DEPENDENCIES = "";
       
        
        
        
        
        
        
        #region Firebase-analytics
        public static string FIREBASE_DEPENDENCIES= "implementation 'com.google.firebase:firebase-analytics:20.1.0'";
        public static string FIREBASE_IMP_DEPENDENCIES= "implementation 'com.yd.sdk:analysisimp:1.0.0'";
        public static string FIREBASE_MANIFEST =
            "/Packages/yd_sdkmanager/Plugins/Android/Firebase/AndroidManifest.xml";
        
        public static string FIREBASE_GOOGLE_PLAY_SERIVCES =
            "/Packages/yd_sdkmanager/Plugins/Android/Firebase/res/values/google-services.xml";
        
        #endregion

        #region Firebase-crashlytics

        public static string FIREBASE_CRASHLYTICS_DEPENDENCIES= "implementation 'com.google.firebase:firebase-crashlytics:18.2.1'";
        public static string FIREBASE_BASE_PROJECT_dependencies = "classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'";
        public static string FIREBASE_LAUNCHER_PLUGINS = "apply plugin: 'com.google.firebase.crashlytics'";
        

        #endregion

        #region Firebase-PerformanceMonitoring

        public static string FIREBASE_PERF_DEPENDENCIES = "implementation 'com.google.firebase:firebase-perf:20.0.2'";
        public static string FIREBASE_PERF_BASE_PROJECT_dependencies = "classpath 'com.google.firebase:perf-plugin:1.4.0'";
        public static string FIREBASE_PERF_LAUNCHER_PLUGINS = "apply plugin: 'com.google.firebase.firebase-perf'";

        #endregion

        #region Firebase-RemoteConfig
        
        public static string FIREBASE_REMOTECONFIG_DEPENDENCIES= "implementation 'com.google.firebase:firebase-config:21.0.1'";
        public static string FIREBASE_REMOTECONFIG_IMP_DEPENDENCIES= "implementation 'com.yd.sdk:other-remoteconfig:1.0.0'";
        
        #endregion
        
        

        #region Facebook
        public static string FACEBOOK_DEPENDENCIES= "implementation 'com.facebook.android:facebook-android-sdk:[5,6)'";
        public static string FACEBOOK_IMP_DEPENDENCIES= "implementation 'com.yd.sdk:analysisFacebook:1.0.0'";
        public static string FACEBOOK_MANIFEST =
            "/Packages/yd_sdkmanager/Plugins/Android/Facebook/AndroidManifest.xml";

        public static string FACEBOOK_RES_VALUES_STRING =
            "/Packages/yd_sdkmanager/Plugins/Android/Facebook/res/values/strings.xml";
        
        #endregion

      
        #region AppsFlyer

        public static string APPSFLYER_DEPENDENCIES= "implementation 'com.appsflyer:af-android-sdk:6.2.3'\n\t" +
                                                     "implementation 'com.android.installreferrer:installreferrer:2.2'";
        public static string APPSFLYER_IMP_DEPENDENCIES= "implementation 'com.yd.sdk:analysisappsflyer:1.0.0'";
        public static string APPSFLYER_MANIFEST =
            "/Packages/yd_sdkmanager/Plugins/Android/AppsFlyer/AndroidManifest.xml";

        #endregion
        
        #region Adjust

        public static string ADJUST_DEPENDENCIES= "implementation 'com.adjust.sdk:adjust-android:4.28.2'\n\t" +
                                                     "implementation 'com.android.installreferrer:installreferrer:2.2'";
        public static string ADJUST_IMP_DEPENDENCIES= "implementation 'com.yd.sdk:analysisadjust:1.0.0'";
        public static string ADJUST_MANIFEST =
            "/Packages/yd_sdkmanager/Plugins/Android/Adjust/AndroidManifest.xml";

        #endregion
        
        
        
        
        public static string GetFullPath(string path,bool needReplace=false)
        {
            if(_isUsePackageCache && string.IsNullOrEmpty(_rootPath))
                _rootPath = FindSDKRootPath(SDK_PACKAGENAME);

            return needReplace
                ? (_isUsePackageCache
                    ? _rootPath + path.Replace("/Packages/yd_sdkmanager", "")
                    : Application.dataPath.Replace("/Assets", path))
                : Application.dataPath + path;
        }

        public static string FindSDKRootPath(string packageName)
        {
            string result = null;
            var packageCache = Application.dataPath.Replace("Assets", "Library/PackageCache");
            var packageDirectoryInfo = new DirectoryInfo(packageCache);
            foreach (var directory in packageDirectoryInfo.GetDirectories())
            {
                if (directory.Name.StartsWith(packageName))
                {
                    result = directory.FullName;
                    break;
                }
            }

            return result;
        }

    }

}

